package com.example.wujinapi.comm;
import lombok.Synchronized;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class MyLog{
    public static void WriteLog(String FileName, String inputStr){
            Lock lock = new ReentrantLock();
            try {
                lock.lock();
                //BufferedWriter out = new BufferedWriter(new File(System.getProperty("user.dir"),FileName+".txt"));
                /*
                out.write(inputStr);
                out.close();
                * */
                File file = new File(System.getProperty("user.dir"), FileName + ".txt");
                FileWriter fw = new FileWriter(file);
                fw.write(inputStr);
                fw.flush();
                fw.close();
                System.out.println("文件创建成功！");
            } catch (IOException e) {
                System.out.println("文件创建失败！");
                e.printStackTrace();
            }
            finally {
                lock.unlock();
            }
    }
    public void WriteMsgToFile(String FileName, String inputStr){
        try {
            File file = new File(System.getProperty("user.dir"), FileName + ".txt");
            FileWriter fw = new FileWriter(file);
            fw.write(inputStr);
            fw.flush();
            fw.close();
            System.out.println("文件创建成功！");
        } catch (IOException e) {
            System.out.println("文件创建失败！");
            e.printStackTrace();
        }
    }
}
